classdef TestUtilityFunction < matlab.unittest.TestCase

    properties
        OriginalPath
        util_fun
        util_fun_cal
        xi
    end

    methods (TestMethodSetup)
        function createFixture(testCase)
            testCase.OriginalPath = path;
            testCase.addTeardown(@path,testCase.OriginalPath);

            addpath('../');
            addpath('../../UtilityFunctions');

            par =  table2struct(readtable(['../parameters/' ...
                                'distributions_par.csv']));
            
            testCase.xi = par.xi;
            epsilon = 0.3;

            testCase.util_fun = UtilityFunction(epsilon, testCase.xi);
            testCase.util_fun_cal = UtilityQuasiLinear('epsilon',epsilon);
        end
    end

    methods (Test)

        function test_constructor(testCase)
            testCase.util_fun
        end

        function test_U(testCase)
            actVal = testCase.util_fun.U(2, 100);
            expVal = testCase.util_fun_cal.utility(2, 100,testCase.xi);
            testCase.verifyEqual(actVal, expVal, 'AbsTol', 1e-6)
        end


        function test_dUdl(testCase)
            actVal = testCase.util_fun.dUdl(100);
            expVal = testCase.util_fun_cal.dUdl(100,testCase.xi);
            testCase.verifyEqual(actVal, expVal, 'AbsTol', 1e-6)
        end                

        
        function test_mtax(testCase)
            actVal = testCase.util_fun.mtax(2000, 15);
            expVal = testCase.util_fun_cal.mtax(2000,15,testCase.xi);
            testCase.verifyEqual(actVal, expVal, 'AbsTol', 1e-6)
        end     
        
        
        function test_Udot(testCase)
            actVal = testCase.util_fun.Udot(100, 15);
            expVal = testCase.util_fun_cal.udot(100, 15,testCase.xi);
            testCase.verifyEqual(actVal, expVal, 'AbsTol', 1e-6)
        end        

        
        function test_c(testCase)
            actVal = testCase.util_fun.c(1.9868, 100);
            expVal = testCase.util_fun_cal.c(1.9868, 100,testCase.xi);
            testCase.verifyEqual(actVal, expVal, 'AbsTol', 1e-6)
        end          
    end

end
